
var email_maxstrlen = 20;
var password_maxstrlen = 16;

function getStrleng(str, maxstrlen) {
    var myLen = 0;
    i = 0;
    for (; (i < str.length) && (myLen <= maxstrlen * 2); i++) {
        /*if (str.charCodeAt(i) > 0 && str.charCodeAt(i) < 128)
            myLen += 1;
        else*/
        myLen += 2;
    }
    return myLen;
}

function checkEmailLeng(c) {
    var len = email_maxstrlen;
    var str = c.value;
    var myLen = getStrleng(str, len);

    if (myLen > len * 2) {
        c.value = str.replace(/^\s+|\s+$/g,"").substring(0, i + 1);
    }
    else {
        c.value = str.replace(/^\s+|\s+$/g,"");
    }
}



function checkPasswordLeng(c) {
    var len = password_maxstrlen;
    var str = c.value;
    var myLen = getStrleng(str, len);

    if (myLen > len * 2) {
        c.value = str.replace(/^\s+|\s+$/g,"").substring(0, i + 1);
    }
    else {
        c.value = str.replace(/^\s+|\s+$/g,"");
    }
}